;(function () {
  new Vue({
    el: '#cEnd',
    data: {
      page: 1,
      limit: ['10'],
      pageCounts: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
      data: {companys: []},
      quanxian: JSON.parse(window.localStorage.getItem('permissions')),
      orders: '#',
      columns: '#',
      keyword: '',
			flag: false,
			tabArr: [{name: '待审核', count: '0', state: 'WA'}, {name: '已上架', count: '0', state: 'PA'}, {name: '审核拒绝', count: '0', state: 'RJ'}],
			auditState: 'WA',
			industryArr: [],
			industryActive: [],
			companyInfo: {},
			checkFlag: false,
			companyIds: [],
			checkRight: false,
			refuseMemo: '',
			refuseFlag: false
    },
    filters: {
      framtTime (time) {
				if (!time) return '--'
        return hlDateUtil.formatDate(time,'yyyy-MM-dd HH:mm:ss')
      },
      formatDate: function(time) {
        if (!time) return '--'
        return hlDateUtil.formatUTCDate(time,'yyyy-MM-dd')
      },
			auditState (item) {
				let res;
				switch (item) {
					case 'WA':
						res = '待审核'
						break;
					case 'PA':
						res = '已上架'
						break;
					case 'RJ':
						res = '审核拒绝'
						break;
					default:
						res = '--'
						break;
				}
				return res
			}
    },
    methods: {
      //最后更新时间
      updateTime () {
				setTimeout(() => {
					this.companyDt()
				}, 300)
        if (this.columns != 'UT') {
          this.columns = 'UT';
          this.orders = 'A';
          return
        }
        if (this.orders == 'A') {
          this.orders = 'D'
          return
        }
        if (this.orders == 'D') {
          this.orders = 'A'
          return
        }
      },
      //创建时间
      createTime () {
				setTimeout(() => {
					this.companyDt()
				}, 300)
        if (this.columns != 'CT') {
          this.columns = 'CT';
          this.orders = 'A';
          return
        }
        if (this.orders == 'A') {
          this.orders = 'D'
          return
        }
        if (this.orders == 'D') {
          this.orders = 'A'
          return
        }
      },
			//批量审批
			batchApproval () {
				this.checkFlag = true;
			},
			//取消
			cancelBatchApproval () {
				this.checkFlag = false;
				this.checkRight = false;
				this.companyIds = []
			},
			//所属行业
			industry () {
				hlhttp.get({
					url: 'jwk/company_industrys',
					data: {valid: 'Y'},
					success: (data) => {
						this.industryArr = hlArrayUtil.replaceData(data, [{key: 'industryName', rKey: 'name'}, {key: 'industryCode', rKey: 'code'}]);
					}
				})
			},
			//选择行业
			selIndustry (arr) {
				this.industryActive = [arr[0].code]
			},
			//新增企业
			addCompany () {
				hlUrlUtil.goTo('jwkSquareAdd',{ddtab: true},true)
			},
			//行业配置
			industryConfig () {
				hlUrlUtil.goTo('jwkIndstry',{ddtab: true},true)
			},
			//导航赛选
			tabScreen (item) {
				this.page = 1;
				this.auditState = item.state;
				setTimeout(() => {
					this.companyDt()
				}, 50)
			},
			//重置
			resetDt () {
				this.keyword = '';
				this.industryActive = [];
				this.auditState = 'WA';
				this.page = 1;
				this.columns = '#';
				this.orders = '#';
				this.companyDt()
			},
			eventPage (arr) {
				this.limit = [arr[0].code]
				this.companyDt()
			},
			//获取企业列表
			companyDt () {
				this.companyStateCount()
				hlhttp.get({
					url: 'jwk/companys',
					data: {
						keyword: this.keyword ? this.keyword : '#',
						industry_code: this.industryActive.length ? this.industryActive[0] : '#',
						audit_state: this.auditState,
						page: this.page,
						page_count: this.limit[0],
						column: this.columns,
						order: this.orders
					},
					success: (data) => {
						this.data = data;
						$("#page").initPage(data.totalPage, this.page, (n) => {
						  if (this.page == n) {
						    return
						  }
						  this.page = n;
						  this.companyDt();
						});
					}
				})
			},
			//获取企业详情
			companyInfoDt (item) {
				hlhttp.get({
					url: 'jwk/company',
					data: {company_id: item.id},
					success: (data) => {
						this.companyInfo = data;
						this.flag = true;
					}
				})
			},
			//关闭详情
			closeInfo () {
				this.flag = false;
			},
			//审核通过
			oneRight () {
				let ids = JSON.parse(JSON.stringify(this.companyIds))
				hlhttp.put({
					url: 'jwk/company/_pass',
					data: {company_ids: ids.toString()},
					success: (data) => {
						hl.toast('操作成功')
						this.companyDt()
					}
				})
			},
			//审核拒绝
			oneReject () {
				let ids = JSON.parse(JSON.stringify(this.companyIds))
				hlhttp.put({
					url: 'jwk/company/_reject',
					data: {company_ids: ids.toString(), fail_memo: this.refuseMemo},
					success: (data) => {
						hl.toast('操作成功')
						this.companyDt()
					}
				})
			},
			//详情审核通过
			infoRight () {
				this.flag = false;
				this.companyIds.push(this.companyInfo.id)
				this.oneRight()
			},
			//详情审核拒绝
			infoReject () {
				this.flag = false;
				this.companyIds.push(this.companyInfo.id)
				this.refuseFlag = true;
			},
			//列表审核通过
			listRight (item) {
				this.flag = false;
				this.companyIds.push(item.id)
				this.oneRight()
			},
			//列表审核拒绝
			listReject (item) {
				this.flag = false;
				this.refuseFlag = true;
				this.companyIds.push(item.id)
				// this.oneReject()
			},
			oneRejectRight () {
				this.refuseFlag = false;
				this.checkFlag = false;
				this.checkRight = false;
				this.oneReject()
			},
			//批量审核通过
			moreRight () {
				this.checkFlag = false;
				this.checkRight = false;
				this.oneRight()
			},
			//批量审核拒绝
			moreReject () {
				this.refuseFlag = true;
			},
			//删除
			del (item) {
				hllayer.confirm('确认要删除该此条吗?', () => {
				    hlhttp.delete({
				    	url: 'jwk/company?company_id=' + item.id,
				    	success: (data) => {
				    		hl.toast('操作成功')
				    		this.companyDt()
				    	}
				    })
				})

			},
			//详情删除
			infoDel () {
				this.flag = false;
				this.del({id: this.companyInfo.id})
			},
			//跳转编辑
			goEdit () {
				hlUrlUtil.goTo('jwkIndstryEdit',{ddtab: true, id: this.companyInfo.id},true)
			},
			//企业审批状态数量
			companyStateCount () {
				hlhttp.get({
					url: 'jwk/company_state_count',
					success: (data) => {
						this.tabArr.map(item => {
							switch (item.state){
								case 'WA':
									item.count = data.WACount;
									break;
								case 'PA':
									item.count = data.PACount;
									break;
								case 'RJ':
									item.count = data.RJCount;
									break;
								default:
									item.count = '0';
									break;
							}
						})
					}
				})
			},
			//全选
			checkAllEvent () {
				if (this.companyIds.length) {
					this.companyIds = [];
					this.checkRight = false;
					return
				}
				this.checkRight = true;
				this.data.companys.map(item => {
					this.companyIds.push(item.id)
				})
			},
			//单选
			singleSelection (item) {
				if (this.companyIds.indexOf(item.id) == -1) {
					this.companyIds.push(item.id)
					return
				}
				this.companyIds.splice(this.companyIds.indexOf(item.id), 1)
			},
			//关闭拒绝弹窗
			hidePopRefuse () {
				this.refuseFlag = false;
				this.refuseMemo = '';
			}
    },
    mounted () {
			this.industry()
			this.companyDt()
			this.companyStateCount()
			hlSelectUi()
    }
  })
} ())
